package com.yykt.myapp.controller;

import com.yykt.myapp.entity.User;
import com.yykt.myapp.service.NewUserService;
import com.yykt.myapp.service.UserService;
import com.yykt.myapp.util.JsonResult;
import com.yykt.myapp.vo.ApiUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("mybatis")
@RestController
public class MybatisSample {

    @Autowired
    UserService userService;

    @Autowired
    NewUserService newUserService;

    @GetMapping("findByAk")
    public JsonResult findByAk(@RequestParam String ak) {
        List<ApiUser> user = userService.getUserByAk(ak);
        return JsonResult.success(user);
    }

    @GetMapping("getUserById")
    public JsonResult getUserById(@RequestParam Long id) {
        User user = newUserService.getUserById(id);
        return JsonResult.success(user);
    }

    @PostMapping("insertUser")
    public JsonResult insertUser(@RequestBody User user) {
        newUserService.insertUser(user);
        return JsonResult.success();
    }
}
